<?php
include "conn.php";
$id = $_GET['id'];
$data = showBlogById($id);

function replace($str): string
{
    $pattern = array(
        '/ /',//半角下空格
        '/　/',//全角下空格
        '/\r\n/',//window 下换行符
        '/\n/',//Linux && Unix 下换行符
    );
    $replace = array('&nbsp;', '&nbsp;', '<br />', '<br />');
    return preg_replace($pattern, $replace, $str);
}

?>

<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Blog</title>
</head>
<body>
<div class="back"><a href="index.php">回到首页</a></div>
<div class="article-container">
    <article style="width: 500px;">
        <h1><?php echo $data['title'] ?></h1>
        <div class="pa-container">
            <div class="publishTime"><?php echo $data['publish'] ?></div>
            <div class="author"><?php echo $data['author'] ?></div>
        </div>
        <div><?php echo replace(stripslashes($data['content'])) ?></div>
    </article>
</div>
</body>

</html>

<style>
    .article-container, .back {
        display: flex;
        justify-content: center;

    }

    .pa-container {
        width: 400px;
        margin-left: 20%;
        display: inline-flex;
        margin-bottom: 5px;
    }

    .publishTime {
        margin-right: 25px;
    }
</style>